<template>
	<view class="tea-pay-app">
		<view class="rule info-item">
			<view class="icon">
				<image src="../../../static/room_info.png" style="width:44upx;height:44upx;" />
			</view>
			<view class="value">成为会员</view>
		</view>
		
		<view class="info">
			<view class="money"><text style="font-size:80upx;">￥</text>{{teaConfig.vipMoney}}</view>
		</view>
		<view class="submit-button" @click="toPay">
			去支付
		</view>
	</view>
</template>

<script>
	import util from '@/libs/util.js'
	import globalConfig from '../../../config'
	const baseHttp = globalConfig.API_HOST
		
	export default {
	    data() {
	        return {
				baseHttp: baseHttp,
				teaHouseId: '',
				map: {
					latitude: 39.910925,
					longitude: 116.413384,
					covers: [
						{
						    latitude: 39.909,
						    longitude: 116.39742,
						    iconPath: '../../../static/location.png'
						}, {
						    latitude: 39.90,
						    longitude: 116.39,
						    iconPath: '../../../static/location.png'
						}
					]
				},
				teaHouse: {
					address: "",
					des: "",
					images: "",
					joinTime: "",
					lat: "",
					lon: "",
					name: "",
					remark: "",
					teaHouseId: "",
					tel: ""
				},
				wxCode: "",
				teaConfig: {
					deposit: "",
					vipMoney: "",
					superVipTimes: "",
					subMemberLimit: "",
					remark: ""
				},
				listData: {
					items: [
					]
				}
	        }
	    },
		onLoad(params) {
			this.teaHouseId = params.teaHouseId;
			this.roomId = params.roomId;
			//console.log("teaHouseId:"+this.teaHouseId);
			//console.log("roomId:"+this.roomId);
		},
		onShow() {
			//this.getDataList();	
			//this.getDataList();
			this.getConfigInfo();
			//this.getWxCode();
		},
		components: {
			
		},
		computed: {

		},
	    methods: {
			...util,
			getWxCode() {
				wx.login({
					success: (res) => {
						if (res.code) {
							this.wxCode = res.code;
							console.log(this.wxCode);
						}
					}
				});
			},
			toPay() {
				wx.login({
					success: (res) => {
						if (res.code) {
							this.wxCode = res.code;
							//console.log(this.wxCode);
							
							this.$api.post('/weixin/vip',
							  {
								code: this.wxCode,
								teaHouseId: this.teaHouseId
							  }
							).then((response) => {
							  if (response.ret===1) {
								//console.log(response);
								let json = "{"+response.data+"}";						
								json = json.replace(/'/g,'"');
								json = JSON.parse(json);
								console.log(json);
								
								uni.requestPayment({
									provider: 'wxpay',
									timeStamp: json.timeStamp,
									nonceStr: json.nonceStr,
									package: json.package,
									signType: json.signType,
									paySign: json.paySign,
									success:  (res) => {
										uni.navigateBack({
											delta: 1
										});
									},
									fail: function (err) {
										console.log('fail:' + JSON.stringify(err));
									}
								});
															
							  } else {
								this.$Message.error(response.msg)
							  }
							});
						}
					}
				});
				
			},
			getTeaHouseInfo() {
				this.$api.post('/teaHouse/getById',
				  {
					teaHouseId: this.teaHouseId
				  }
				).then((response) => {
				  if (response.ret===1) {
					this.teaHouse = response.data
				  } else {
					this.$Message.error(response.msg)
				  }
				});
			},
			getConfigInfo() {
				this.$api.post('/teaHouseConfig/getById',
				  {
					teaHouseId: this.teaHouseId
				  }
				).then((response) => {
				  if (response.ret===1) {
					if (response.data) {
					  this.teaConfig = response.data
					  this.teaConfig.deposit = this.teaConfig.deposit/100;
					  this.teaConfig.vipMoney = this.teaConfig.vipMoney/100;
					}
				  } else {
					this.$Message.error(response.msg)
				  }
				})
			},
			getDataList() {
				/*
				{"data":[{"remark":"备注","roomId":3,"roomLevel":0,"roomNO":"10001","roomName":"高级","roomState":0,"roomType":0,"teaHouseId":2,"updateTime":"2020-12-15 16:25:47"},{"remark":"31231","roomId":7,"roomLevel":0,"roomNO":"12312","roomName":"12312","roomState":0,"roomType":0,"teaHouseId":2,"updateTime":"2020-12-23 18:50:20"}],"ret":1,"total":2}
				*/
				uni.showLoading({
					title: '加载中'
				});
				this.$api.post('/room/queryPage',
					{
						teaHouseId: this.teaHouseId
					}
				).then((response) => {
					//for(let i = 0; i )
					//response.data.items = this.setField(response.data, 'show', true);
					//console.log(response.data.items);
					this.listData.items = response.data
					
					/*
					for(let i = 0; i < this.listData.items.length; i++) {
						//console.log(this.listData.items[i]);
						this.listData.items[i]['typeLabel'] = this.getLabelFromOptions(this.formSearchOptions.typeList, this.listData.items[i]['type']);
					}
					*/
					
					uni.hideLoading()
				});
			},
			goPage(url) {
				uni.navigateTo({url: url})
			},
	    }
	}
</script>



<style lang="scss">
	page{
		height: 100%;
	}
	
	.page-section,.page-body,.tea-manager-app{
		height: 100%;
	}

	.tea-pay-app{
		background-color: #F5F4F8;
		height: 100%;
		color:#707070;
		
		.info-item{
			background-color: white;
			display: flex;
			padding: 37upx;
			font-size:28upx;
			border-bottom: 1upx solid #eee;
			.icon{
				
			}
			.value{
				margin-left:20upx;
			}
		}
		
		.info{
			height:217upx;
			text-align: center;
			line-height: 217upx;
			background-color: white;
			margin:30upx 0;
			.money{
				font-weight: bold;
				font-size: 100upx;
			}
		}
		
		.submit-button{
			font-size:40upx;
			margin:0 auto;
			background-color:#3385FF;
			color:white;
			width:646upx;
			height:120upx;
			text-align: center;
			line-height: 120upx;
		}
		
	}
	
</style>

